//计算器发送短信验证码
var get_code=function(){
    var phone = $("#mobile").val();
    if (phone == "") {
        alert("请输入您的手机号!");
        $("#phone").focus();
        return false;
    }
    var partten = /^1[3,5,8,4,7]\d{9}$/;
    if (!partten.test(phone)) {
        alert("手机号错误!");
        $("#phone").focus();
        return false;
    }
    sendCode(phone);
};
$('.yzm').on('click',get_code);
//ajax 请求验证码
function sendCode(phone) {
    //60s定时器
    var is_status = false;
    var wait = 60;
    var t_img;
    $.ajax({
        url: '/Wap/AlonePage/ajaxSendCode',
        dataType: 'json',
        type: 'post',
        data: {phone: phone},
        cache: false,
        async: true,
        success: function (json) {
            if (json.code > 0) {  //no-click
                time_run()
            } else {
                alert(json.msg);
            }
        },
        error: function () {
            alert('请求失败,请稍候重试,谢谢');
        }
    });
    function time_run() {
        var obj = $('.yzm');
        if (wait == 0) {
            is_status = true;
        }
        if (is_status) {
            clearTimeout(t_img);
            obj.on('click', get_code);
            obj.html("发送验证码");
        } else {
            is_status = false;
            obj.off('click');
            obj.html("重新发送"+ wait);
            wait--;
            t_img = setTimeout(function () {
                time_run();
            }, 1000);
        }
    }
}
